package com.dly.blog.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.dly.blog.utile.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/11 15:08
 */
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //todo 创建人
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "createUser", SecurityUtils::getUserId, String.class);
        this.strictInsertFill(metaObject, "deleted", () -> 0, Integer.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //todo 更新人
        this.strictUpdateFill(metaObject, "updateUser", SecurityUtils::getUserId, String.class);
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
    }


}
